<?php

class Application_Model_DbTable_Books extends Zend_Db_Table_Abstract {

    protected $_name = 'books';

    public function getBook($id) {
        $id = (int) $id;
        $row = $this->fetchRow('id = ' . $id);
        if (!$row) {
            throw new Exception("Could not find row $id");
        }
        return $row->toArray();
    }

    public function addBook($author, $title, $file) {
        $data = array(
            'author' => $author,
            'title' => $title,
            'image' => $file,
        );
        $this->insert($data);
    }

    public function updateBook($id, $author, $title, $file) {
        $data = array(
            'author' => $author,
            'title' => $title,
            'image' => $file,
        );
        $this->update($data, 'id = ' . (int) $id);
    }

    public function deleteBook($id) {
        $this->delete('id =' . (int) $id);
    }

}
